﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace CaveArt.Util.ZenGraph
{
    public class DataLine
    {
        private object[] obj = null;

        public DataLine(Configuration cfg, string line)
        {
            string[] s = line.Split(cfg.Seperaters);
            if (s.Length == cfg.Columns.Count)
            {
                obj = new object[cfg.Columns.Count];
     
                int i = 0;
                DateTime result;
                foreach (DataColumn c in cfg.Columns)
                {
                    switch (c.eType)
                    {
                        case DataType.eString:
                            obj[i] = s[i];
                            break;
                        case DataType.eNumber:
                            obj[i] = Convert.ToInt32(s[i]);
                            break;
                        case DataType.eDateTime:
                            if (DateTime.TryParseExact(s[i], cfg.TimeFormat, null, System.Globalization.DateTimeStyles.None, out result))
                            {
                                obj[i] = result;
                            }
                            else
                            {
                                Debug.Fail("DateTime type has invalid data.");
                            }
                            break;
                        case DataType.eNotDefined:
                            Debug.Fail("DataType not initialized.");
                            break;
                    }
                    i++;
                }
            }
        }
    }

    public class DateFormatProvider : IFormatProvider, ICustomFormatter
    {
        #region IFormatProvider Members

        public object GetFormat(Type formatType)
        {
            if (formatType == typeof(ICustomFormatter))
            {
                return this;
            }
            else
                return null;
        }

        #endregion

        #region ICustomFormatter Members

        public string Format(string format, object arg, IFormatProvider formatProvider)
        {
            string result = arg.ToString();

            // if (result
            //

            return result;
        }

        #endregion
    }
 
}
